var e = require("../../../component/WxNotificationCenter/WxNotificationCenter.js"), a = getApp();

Page({
    data: {
        code: "",
        weddingOrderId: ""
    },
    getPhoneNumber: function(e) {
        null != e.detail.iv ? this.loginWithPhone(e.detail.iv, e.detail.encryptedData, this.data.code) : a.util.showToast("您已拒绝");
    },
    loginWithPhone: function(t, o, n) {
        a.network.post({
            url: a.url.WechatPhoneLogin,
            params: {
                iv: t,
                encryptedData: o,
                code: n
            },
            before: function() {
                wx.showLoading({
                    title: "正在登录"
                });
            },
            success: function(t) {
                console.log(t.data), wx.hideLoading(), 1 == t.data.result ? (a.util.showToast(t.data.message), 
                a.globalData.accessToken = t.data.data.accessToken, a.globalData.firstLogin = !0, 
                a.globalData.authToken = t.data.data.authToken, wx.setStorageSync(a.storage.accessToken, t.data.data.accessToken), 
                wx.setStorageSync(a.storage.role, t.data.data.role), wx.setStorageSync(a.storage.hunyu, t.data.data.hunyu), 
                wx.setStorageSync(a.storage.authToken, t.data.data.authToken), a.util.updateUserInfo(), 
                a.util.lastAccessServer(), e.postNotificationName("didLoginSuccess"), wx.navigateBack()) : 2 == t.data.result ? wx.navigateTo({
                    url: "/pages/login/selectRole/selectRole?phone=" + t.data.data.phone
                }) : a.util.showToast(t.data.message);
            },
            fail: function() {
                wx.hideLoading(), wx.navigateTo({
                    url: "/pages/login/selectRole/selectRole?phone=18883358909"
                }), a.util.showToast("登录失败");
            },
            complete: function() {}
        });
    },
    clickPhone: function(e) {
        wx.navigateTo({
            url: "../login"
        });
    },
    onLoad: function(e) {
        e.weddingOrderId && this.setData({
            weddingOrderId: e.weddingOrderId
        });
    },
    onReady: function() {},
    onShow: function() {
        var e = this;
        wx.login({
            success: function(a) {
                console.log(a.code), e.data.code = a.code;
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});